import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import properties.ScheduleProperties;
import sign.InSign;
import sign.OutSign;

import java.io.IOException;

/**
 * @author liufei
 * @Description
 * @Date 2020/11/2 14:53
 */
public class Main {

    private static final Logger logger = LoggerFactory.getLogger(Main.class);

    public static void main(String[] args) throws SchedulerException, InterruptedException, IOException {
        ScheduleProperties scheduleProperties = new ScheduleProperties();
        // 1、创建调度器Scheduler
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = schedulerFactory.getScheduler();
        // 2、创建JobDetail实例，并与PrintWordsJob类绑定(Job执行内容)
        JobDetail inSignDetail = JobBuilder.newJob(InSign.class)
                .withIdentity("上班签到", "签到组1").build();
        // 3、构建Trigger实例,调度执行
        Trigger inSignTrigger = TriggerBuilder.newTrigger().withIdentity("触发器1", "触发组1")
                .startNow()//立即生效
                .withSchedule(
                        CronScheduleBuilder.cronSchedule(scheduleProperties.getInTime())
                ).build();
        //4、执行
        scheduler.scheduleJob(inSignDetail, inSignTrigger);
        scheduler.start();
        logger.info("--------上班打卡调度器已启动------------");

        // 2、创建JobDetail实例，并与PrintWordsJob类绑定(Job执行内容)
        JobDetail outSignDetail = JobBuilder.newJob(OutSign.class)
                .withIdentity("下班签到", "下班签到组1").build();
        // 3、构建Trigger实例,调度执行
        Trigger outSignTrigger = TriggerBuilder.newTrigger().withIdentity("触发器2", "触发组2")
                .startNow()//立即生效
                .withSchedule(
                        CronScheduleBuilder.cronSchedule(scheduleProperties.getOutTime())
                ).build();
        //4、执行
        scheduler.scheduleJob(outSignDetail, outSignTrigger);
        scheduler.start();
        logger.info("--------下班打卡调度器已启动------------");

    }

}
